Kinetis SDK Demo Applications User Guide  1.0.0-beta
Freescale Semiconductor, Inc.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
spi_flash_test.c File Reference
#include <string.h>
#include <stdio.h>
#include "board.h"
#include "pin_mux.h"
#include "gpio_pins.h"
#include "fsl_gpio_driver.h"
#include "spi_flash/spi_flash.h"
#include "fsl_device_registers.h"
#include "fsl_misc_utilities.h"
#include "cmd_handle.h"
#include "char_handle.h"

Macros

#define SF_DEFAULT_SPEED
 
#define SF_DEFAULT_MODE
 
#define SF_DEFAULT_CS
 
#define SF_DEFAULT_BUS
 

Functions

int32_t spi_cs_activate (spi_slave_dev *spi)
 
int32_t spi_cs_deactivate (spi_slave_dev *spi)
 
static int32_t do_spi_flash_probe (int32_t argc, char *argv[])
 
static const char * spi_flash_update_block (spi_flash *flash, uint32_t offset, size_t len, const int8_t *buf, int8_t *cmp_buf, size_t *skipped)
 Write a block of data to SPI flash, first checking if it is different from what is already there. More...
 
static int32_t spi_flash_update (spi_flash *flash, uint32_t offset, size_t len, const int8_t *buf)
 
static int32_t do_spi_flash_read_write (int32_t argc, char *argv[])
 
static int32_t sf_parse_len_arg (char *arg, uint32_t *len)
 This function computes the length argument for the erase command. More...
 
static int32_t do_spi_flash_erase (int32_t argc, char *argv[])
 
static int32_t do_spi_flash_print_usage (int32_t argc, char *argv[])
 
void main (void)
 

Variables

static spi_flash * flash
 
cmd_tbl_t sf_cmd_tbl [SPI_FLASH_FUNC_NUM]
 

Macro Definition Documentation

#define SF_DEFAULT_BUS
#define SF_DEFAULT_CS
#define SF_DEFAULT_MODE
#define SF_DEFAULT_SPEED

Function Documentation

static int32_t do_spi_flash_erase ( int32_t  argc,
char *  argv[] 
)
static
static int32_t do_spi_flash_print_usage ( int32_t  argc,
char *  argv[] 
)
static
static int32_t do_spi_flash_probe ( int32_t  argc,
char *  argv[] 
)
static
static int32_t do_spi_flash_read_write ( int32_t  argc,
char *  argv[] 
)
static
void main ( void  )
static int32_t sf_parse_len_arg ( char *  arg,
uint32_t *  len 
)
static

The length on which the command is to operate can be given in two forms:

  1. <cmd> offset len - operate on <'offset', 'len')
  2. <cmd> offset +len - operate on <'offset', 'round_up(len)') If the second form is used and the length doesn't fall on the sector boundary, than it will be adjusted to the next sector boundary. If it isn't in the flash, the function will fail (return 1).
Parameters
[in]arglength specification (i.e. both command arguments)
[out]lencomputed length for operation
Returns
: 1: success -1: failure (bad format, bad address).
int32_t spi_cs_activate ( spi_slave_dev *  spi)
int32_t spi_cs_deactivate ( spi_slave_dev *  spi)
static int32_t spi_flash_update ( spi_flash *  flash,
uint32_t  offset,
size_t  len,
const int8_t *  buf 
)
static

Update an area of SPI flash by erasing and writing any blocks which need to change. Existing blocks with the correct data are left unchanged.

Parameters
[in]flashflash context pointer
[in]offsetflash offset to write
[in]lennumber of bytes to write
[in]bufbuffer to write from
Returns
0 if ok, 1 on error
static const char* spi_flash_update_block ( spi_flash *  flash,
uint32_t  offset,
size_t  len,
const int8_t *  buf,
int8_t *  cmp_buf,
size_t *  skipped 
)
static

If the data being written is the same, then *skipped is incremented by len.

Parameters
[in]flashflash context pointer
[in]offsetflash offset to write
[in]lennumber of bytes to write
[in]bufbuffer to write from
[in]cmp_bufread buffer to use to compare data
[in]skippedCount of skipped data (incremented by this function)
Returns
NULL if OK, else a string containing the stage which failed

Variable Documentation

spi_flash* flash
static